<?php

/*
 * This file will used for viewing an attachment.
 * 
 * Created by: Peter Agno Jr.
 * Date created: October 9, 2011
 */

// Start - Checker for those users who will just go to the page by typing directly in the url.
if ($_POST) { 
    include("siteTop.php"); 
    include('includes/siteConfig.php'); 
    
    // Get the document id via post method
    $documentId = $_POST['documentId'];
    
    if(isset($_POST['documentsToReceive']))
    {
        $documentId = $_POST['documentsToReceive'];
        
    }
    else if(isset($_POST['documentsOnHand']))
    {
        $documentId = $_POST['documentsOnHand'];
    }
    else if(isset($_POST['taggedDocuments']))
    {
         $documentId = $_POST['taggedDocuments'];
    }
    else if(isset($_POST['documentId']))
    {   // Used by the search function
         $documentId = $_POST['documentId'];
    }
    // Connect to database
    $connect = mysql_connect($hostName,$rootName,$dBasePassword) or die ('Unable to connect!');
    mysql_select_db($dBaseName) or die ('Unable to select database!');
?>

<!-- HEADER START -->
    <!--JAVASCRIPT SOURCES-->
    <script src="js/jquery-1.6.2.min.js"></script>
    
    <!--ACTUAL JS SCRIPTS AND JQUERIES-->
    <script type="text/javascript">
        jQuery(document).ready(function(){
            addDocInfo(".attachInfoDiv", "<?php echo $documentId; ?>", "fromBase");     // Add Document Information
            addLogInfo(".logInfoDiv", "<?php echo $documentId; ?>", "fromBase");        // Add Logs
            addAttchTransac(".attachTransInfoDiv", "<?php echo $documentId; ?>", "fromBase", "false");      // Add Attachment Transactions

            <?php
                // currently commented out, will be used for testing purposes
                // INCLUDE JQUERUES FOR THEATRE BOX IN SHOWING AN ATTACHMENT
//                include('includes/jqueries/jQShwAttchInfo.php'); 
            ?>
            
            // *** Start - The following are the includes for viewing page of attachment. ***
            <?php 
                // INCLUDE JQUERUES FOR SHOWING DOCUMENT INFORMATION
                include('includes/jqueries/jQShowDocInfo.php'); 
                
                // INCLUDE JQUERUES FOR SHOWING DOCUMENT LOG
                include('includes/jqueries/jQShowDocLog.php');
                
                // INCLUDE JQUERIES FOR INFORMATION BUTTON
                include('includes/jqueries/jQLogInfoIcn.php');
                
                // INCLUDE JQUERIES FOR ADDING THE ATTACHMENT TRANSACTION SCREENLETS
                include('includes/jqueries/jQAttchTransac.php');
                
                // INCLUDE JQUERUES FOR SEND ATTACHMENT SCREENLET
                // Flag for showing the send attachment screenlet when onloading
                ?>
                var changePos = true;
                <?php
                include('includes/jqueries/jQSendAttach.php');
                
                // INCLUDE JQUERUES FOR ACKNOWLEDGE SENT ATTACHMENT SCREENLET
                include('includes/jqueries/jQAckSentAttach.php');
                
                // INCLUDE JQUERUES FOR ARCHIVE ATTACHMENT
                include('includes/jqueries/jQArchiveAttach.php');
            ?>
            // *** Start - The following are the includes for viewing page of attachment. ***
                
        }); // END - (DOCUMENT READY FUNCTION)
    </script>
    <!-- HEAD END -->
    
<?php include("siteMiddle.php"); ?>

<div id="content">
    <h1>View Attachment</h1>
    
    <?php
    // Check permission
    $thePermissions = array('VIEWATTCH');
    if ( checkPermission( $thePermissions, $userId ) == true ) {
    ?>
    
        <div class="messageBox successMessage successMessage_fromBase" style="display:none;">
            <div id="successMessages" class="successMessages_fromBase"></div>
        </div>

        <!-- Display attachment information -->
        <?php include("attachmentInfo.php");  ?>

        <!-- Display logs of the attachment -->
        <?php include("displayLogs.php");  ?>

        <!-- Display transactions for the attachment -->
        <?php include("attachmentTransaction.php"); ?>
    
    <?php
    }
    else {
        echo "<div class='noPermissionMsgBox noPermissionMsg' style='border: 2px solid red'><div id='noPermissionMsgs'>You have no permission to view this page.</div></div>";
    }
    // End checking permission
    ?>
</div>
    
    <!-- testing out the theatre box, currently commented out, will be used for testing purposes -->
<!--    <input type="button" class ="siteGreenButton shwAttchInfo" id="theatre__<?php echo $documentId; ?>" value="Test">-->
    
<?php     
    include ("siteBottom.php");
}   // End - Checker for those users who will just go to the page by typing directly in the url.
else {
 echo "You are not authorized to view this page. This incident will be reported immediately.";
}
?>

